package com.atguigu.gulimall.seckill.scheduled;

import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * @EnableScheduling 开启支持定时任务  TaskSchedulingAutoConfiguration自动配置类
 * @EnableAsync 开启异步任务功能 TaskExecutionAutoConfiguration自动配置类  通过spring.task.execution属性绑定配置
 *
 * 使用异步任务解决：使用异步+定时任务来完成定时任务不阻塞功能
 */
@Slf4j
@Component
//@EnableAsync
//@EnableScheduling
public class HelloSchedule {

//    @Async
    @Scheduled(cron = "* * * ? * 6")
    public void hello() throws InterruptedException {
      log.info("hello...");
      Thread.sleep(3000); //不加异步会造成阻塞  TaskSchedulingProperties==》spring.task.scheduling size默认为1
    }
}
